﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>site</title>
     <link href="../../Content/element-ui/lib/theme-chalk/index.css" rel="stylesheet" type="text/css" />
    <script src="../../Content/vue-2.6.11/dist/vue.min.js" type="text/javascript"></script>
    <script src="../../Content/element-ui/lib/index.js" type="text/javascript"></script>
    <script src="../../Content/axios/dist/axios.min.js" type="text/javascript"></script>
</head>
<body>
    <div id="app">
      <el-form ref="form" :model="form" :rules="rules" size="small" style="margin-top:50px;margin-left:20px;width:460px;" label-width="100px">
       <el-form-item label="站点名称" prop="sitename">
         <el-input v-model="form.sitename" maxlength="100" show-word-limit ></el-input>
      </el-form-item>
      <el-form-item label="站点域名" prop="siteurl">
         <el-input v-model="form.siteurl"  maxlength="200" show-word-limit ></el-input>
      </el-form-item>
       <el-form-item label="站点关键字" prop="sitekeyword">
         <el-input v-model="form.sitekeyword"  maxlength="200" show-word-limit ></el-input>
      </el-form-item>
       <el-form-item label="描述" prop="sitedescption">
         <el-input  type="textarea"  :rows="5" v-model="form.sitedescption"  maxlength="500" show-word-limit ></el-input>
      </el-form-item>
       <el-form-item label="ICP" prop="icp">
         <el-input v-model="form.icp"  maxlength="100" show-word-limit ></el-input>
      </el-form-item>
       <el-form-item label="联系人" prop="linkman">
         <el-input v-model="form.linkman"  maxlength="50" show-word-limit ></el-input>
      </el-form-item>
       <el-form-item label="联系电话" prop="linktel">
         <el-input v-model="form.linktel"  maxlength="50" show-word-limit ></el-input>
      </el-form-item>
       <el-form-item label="地址" prop="dizhi">
         <el-input v-model="form.dizhi"  maxlength="200" show-word-limit ></el-input>
      </el-form-item>
       <el-form-item label="邮箱" prop="email">
         <el-input v-model="form.email"  maxlength="50" show-word-limit ></el-input>
      </el-form-item>

   <el-form-item>
    <el-button type="primary" icon="el-icon-circle-check" v-on:click="onSubmit('form')">保存</el-button>
  </el-form-item>
  </el-form>


    </div>
   
     <script type="text/javascript">
        

		new Vue({
            el : '#app',
            data(){
                return {
                    form : 
                    {
                        id:1,
                        sitename : '',
                        siteurl :'',
                        sitekeyword : '',
                        sitedescption :'',
                        icp :'',
                        linkman :'',
                        linktel :'',
                        dizhi :'',
                        email :''
                    },
					ueditor : null,
                    rules : 
                    {
                        sitename : [{
                            required : true,
                            message : '请输入标题',
                            trigger : 'blur'
                        }],
                        sitekeyword : [{
                            required : true,
                            message : '请输入优化关键字',
                            trigger : 'blur'
                        }],
                        sitedescption : [{
                            required : true,
                            message : '请输入优化描述信息',
                            trigger : 'blur'
                        }]
                    }
                }
            },
            created() {
               this.loadinfo();
            },
            methods : 
            {
                onSubmit(formName){
					var that = this;
                    this.$refs[formName].validate((valid) => 
                    {
						if(valid){
                            axios.post('/Site/savesite', that.transformRequest(that.form)).then(function(response){
                                console.log(response.data)
                                var result = JSON.parse(response.data);
                                if(result.success){
                                    that.$message({
                                        message : "保存成功",
                                        type : 'success'
                                    });
                                }
                                else{
                                    that.$message.error("保存失败");
                                }
                                
                            }).catch(function(error){
                                console.log(error);
                            });
                        }
                        else{
                            console.log('error submit!!');
                            return false;
                        }
                    });
                },
				transformRequest(data){
                    let params = '';
                    for(let index in data){
                        params += index + '=' + data[index] + '&';
                    }
                    return params;
                },
				loadinfo(){
                    let that = this;
                    axios.post('/Site/getsiteinfo', that.transformRequest({
                        id : that.form.id
                    })).then(function(response){
                        if(response.data != ""){
                            that.form = response.data;
                        }
                    })
                    
                }
                
            }
        });




    </script>
</body>
</html>
